<%@ page language="java"
	import="com.skyline.jfs.namespace.model.*,java.util.List"
	contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JFS LS</title>
<%
	JFSLsResult lsResult = (JFSLsResult) request.getAttribute("lsResult");
	List<JFSDirectory> dirs = lsResult.getDirs();
	List<JFSFile> files = lsResult.getFiles();
	JFSDirectory currentDir=lsResult.getCurrentDir();
	String currentPath="";
	if(currentDir.getPath()!=null)
	{
		currentPath=currentDir.getPath();
	}
%>
<script type="text/javascript">
function modifyDir()
{
	var idRadio = document.all.Id;
	for ( var i = 0; i < idRadio.length; i++) {
		if (idRadio[i].checked == true) {
			location.href = "../modifyDir/" + idRadio[i].value + ".html";//alert(jobNumRadio[i].value);
			break;
		}
		//alert(jobNumRadio[i].value);
		if (i == idRadio.length - 1) {
			alert("Please choose the directory which you want to modify!");
		}
	}
}</script>
</head>
<body>
<table>
	<tr>
		<td width="240" valign="top"><%@ include file="../adminNavi.jsp"%>
		</td>
		<td valign="top">
		<%
		if(currentPath.equals(""))
		{
			out.println("<font color='red'>No such a directory!</font><br>");
		}
		%>
		<form action="/JFS/namespace/ls.html" method="get">
		<input type="text" name="currentDir" id="currentDir" value="<%=currentPath %>" size="80"/>
		<input type="submit" value="Go"/>
		</form>
		<br>
		<table width="100%">
			<tr bgcolor='#a1a1a1'>
				<td><input type='radio' id='Id' name='Id' value='0' style="display:none"/></td>
				<td>ID</td>
				<td>Name</td>
				<td>Size</td>
				<td>Permission</td>
				<td>Created Time</td>
				<td>Update Time</td>
			</tr>
			<%
			int subDirNum=dirs.size();
			for(int i=0;i<subDirNum;i++){
				JFSDirectory d=dirs.get(i);
				if (i % 2 == 1)
					out.println("<tr bgcolor='#f1f1f1'>");
				else
					out.println("<tr>");
				out.println("<td><input type='radio' id='Id' name='Id' value='"
						+ d.getId() + "'/></td>");
				out.println("<td>"+d.getId()+"</td>");
				out.println("<td><a href='"+d.getId()+".html'>"+d.getName()+"</a></td>");
				out.println("<td>0</td>");
				if(d.getPermission()==0){
					out.println("<td>r</td>");
				}
				else if(d.getPermission()==1){
					out.println("<td>rw</td>");
				}
				else{
					out.println("<td>rwx</td>");
				}
				out.println("<td>"+d.getCreatedTime().toLocaleString()+"</td>");
				out.println("<td>"+d.getUpdateTime().toLocaleString()+"</td>");
				out.println("</tr>");
			}
			%>
			<tr>
				<td colspan='7' align="right"><input type="button" name="createDir"
					onclick="location.href='/JFS/namespace/createDir/<%=currentDir.getId() %>.html'" value="Create Dir"> <input
					type="button" name="modify" onclick="modifyDir()" value="modify">
				<input type="button" name="delete" onclick="deleteDir()" value="delete"></td>
			</tr>
		</table>
		<table width="100%">
			<tr bgcolor='#a1a1a1'>
			<td><input type='radio' id='fileId' name='fileId' value='0' style="display:none"/></td>
				<td>ID</td>
				<td>File Name</td>
				<td>Size</td>
				<td>Replic Num</td>
				<td>Created Time</td>
				<td>permission</td>
			</tr>
			<%
			int subFileNum=files.size();
			for(int i=0;i<subFileNum;i++){
				JFSFile file=files.get(i);
				if (i % 2 == 1)
					out.println("<tr bgcolor='#f1f1f1'>");
				else
					out.println("<tr>");
				out.println("<td><input type='radio' id='fileId' name='fileId' value='"
						+ file.getId() + "'/></td>");
				out.println("<td>"+file.getId()+"</td>");
				out.println("<td>"+file.getName()+"</td>");
				out.println("<td>"+file.getSize()/1024+" KB</td>");
				out.println("<td>"+file.getReplicNum()+"</td>");
				out.println("<td>"+file.getCreatedTime().toLocaleString()+"</td>");
				if(file.getPermission()==0){
					out.println("<td>r</td>");
				}
				else if(file.getPermission()==1){
					out.println("<td>rw</td>");
				}
				else{
					out.println("<td>rwx</td>");
				}
				out.println("</tr>");
			}
			%>
		</table>
		</td>
	</tr>
</table>
</body>
</html>